import Cookies from 'js-cookie'

const TokenKey = 'token'
const LoginFlag = 'BYG_flag'

export function getLoginFlag() {
  return sessionStorage.getItem(LoginFlag)
}

export function setLoginFlag(data) {
  return sessionStorage.setItem(LoginFlag, data)
}

export function removeLoginFlag() {
  return sessionStorage.removeItem(LoginFlag)
}

export function getToken() {
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token) {
  return sessionStorage.setItem(TokenKey, token)
}

export function removeToken() {
  return sessionStorage.removeItem(TokenKey)
}

export function setName(name) {
  return sessionStorage.setItem("UserName", name)
}
export function getName() {
  return sessionStorage.getItem("UserName")
}
export function removeName() {
  return sessionStorage.removeItem("UserName")
}

export function setUserInfo(name) {
  return sessionStorage.setItem("UserInfo", JSON.stringify(name))
}
export function getUserInfo() {
  let obj = sessionStorage.getItem("UserInfo")
  try{
    obj = JSON.parse(obj)
  }catch (e) {
    obj ={}
  }
 return obj
}
export function removeUserInfo() {
  return sessionStorage.removeItem("UserInfo")
}
//菜单

export function setMenu(name) {
  return sessionStorage.setItem("Menu", JSON.stringify(name))
}
export function getMenu() {
  let menu=[]
  let obj = sessionStorage.getItem("Menu")
  try{
    obj = JSON.parse(obj)
    if (obj.menu) {
      menu=obj.menu
    }
  }catch (e) {
    obj ={}
  }
  return menu
}
export function removeMenu() {
  return sessionStorage.removeItem("Menu")
}
//行政区划

export function setProvinceCityCounty(name) {
  return sessionStorage.setItem("ProvinceCityCounty", JSON.stringify(name))
}
export function getProvinceCityCounty() {
  //获得省市区县
  let obj = sessionStorage.getItem("ProvinceCityCounty")
  let provinceCityCounty=[];
    try{
      obj = JSON.parse(obj)
      if (obj.provinceCityCounty) {
        provinceCityCounty=obj.provinceCityCounty
      }

  }catch (e) {
      provinceCityCounty =[]
  }
  return provinceCityCounty
}
export function removeProvinceCityCounty() {
  return sessionStorage.removeItem("ProvinceCityCounty")
}

// //字典数据
// export function setdictionary(name) {
//   return sessionStorage.setItem("dictionary", name)
// }
// export function getdictionary() {
//   return sessionStorage.getItem("dictionary")
// }
// export function removedictionary() {
//   return sessionStorage.removeItem("dictionary")
// }
